# Python 2.6.4
# Project Euler, Problem 52
# Copyright 2010 Talha Zaman

def samechars(m,n):
    if len(m) == len(n):
        d1 = dict([(x,0) for x in m])
        d2 = dict([(x,0) for x in n])
        for x in m: d1[x] += 1
        for x in n: d2[x] += 1
        if d1==d2: return True
    return False

def checkdigits(n):
    if samechars(str(n), str(2*n)) and \
       samechars(str(n), str(3*n)) and \
       samechars(str(n), str(4*n)) and \
       samechars(str(n), str(5*n)) and \
       samechars(str(n), str(6*n)): return True
    else: return False

for i in range(100001, 200000, 2):
    if checkdigits(i):
        print i
        break
